<template>
	<view class="" style="padding: 0 54rpx;">
		<view class="" style="margin-top: 62rpx;display: flex;justify-content: center;">
			<image src="/static/image/login/logo.png" style="width: 240rpx;height: 240rpx;" mode=""></image>
		</view>
		<view class=""
			style="margin-top: 74rpx;height: 98rpx;padding: 34rpx 50rpx;display: flex;align-items: center;background-color: #FBFBFB;position: relative;">
			<image src="/static/image/login/mobile.png" style="width: 24rpx;height: 32rpx;margin-right: 40rpx;" mode="">
			</image>
			<input type="text" placeholder="请输入手机号" v-model="Info.mobile">

		</view>
		<view class=""
			style="margin-top: 40rpx;height: 98rpx;padding: 34rpx 50rpx;display: flex;align-items: center;background-color: #FBFBFB;position: relative;">
			<image src="/static/image/login/code.png" style="width: 24rpx;height: 32rpx;margin-right: 40rpx;" mode="">
			</image>
			<input type="text" placeholder="请输入验证码" v-model="Info.code">
			<view class="" style="position: absolute;right: 16rpx;top: 18rpx;">
				<view class="" @click="getCodes"
					style="height: 64rpx;border-radius: 10rpx;display: flex;justify-content: center;align-items: center;font-size: 24rpx;padding: 0 20rpx;"
					:style="codeDis ? 'background-color: #DDDDDD;':'color: white;background-color: #FF4D62;'">
					<span>{{codeText}}</span>
				</view>
			</view>
		</view>
		<view class=""
			style="margin-top: 40rpx;height: 98rpx;padding: 34rpx 50rpx;display: flex;align-items: center;background-color: #FBFBFB;">
			<image src="/static/image/login/password.png" style="width: 24rpx;height: 32rpx;margin-right: 40rpx;"
				mode=""></image>
			<input type="password" placeholder="请输入密码" v-model="Info.password">
		</view>
		<view class="">
			<checkbox-group @change="changeCheck">
				<view class="" style="margin-top: 30rpx;display: flex;align-items: center;">

					<checkbox :value="checked"    color="#FF4D62"  /><text style="font-size: 28rpx;">点击注册表示同意</text><text
						style="font-size: 28rpx;color: #FF4D62;" @tap="xieyi">用户注册协议</text>

				</view>
			</checkbox-group>
		</view>


		<view class=""
			style="margin-top: 100rpx;height: 94rpx;color: white;background-color: #FF4D62;border-radius: 10rpx;display: flex;justify-content: center;align-items: center;"
			@click="submit">
			<span>注册</span>
		</view>
		<sc-home></sc-home>
	</view>
</template>

<script>
	import {
		getCode,
		register
	} from '@/common/login.js'
	import {
		setTimeout
	} from 'timers';
	export default {
		data() {
			return {
				Info: {
					mobile: '',
					password: "",
					code: '',
					checked: ''
				},
				checked:'选中',
				codeText: '获取验证码',
				codeDis: false, //是否禁用
				timer: 60
			}
		},
		methods: {
			xieyi(){
				uni.navigateTo({
					url:'/pages/register/xieyi'
				})
			},
			getCodes() {


				getCode({
					mobile: this.Info.mobile
				}).then((res) => {
					if (this.codeDis) return;
					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {

						this.codeDis = true;

						let time = setInterval(() => {
							this.timer--
							this.codeText = this.timer + '秒后重新获取';
							if (this.timer <= 0) {
								clearInterval(time);
								this.codeDis = false;
								this.codeText = '获取验证码'
								this.timer = 60;
							}
						}, 1000)
					}
				}).catch((err) => {
					uni.showToast({
						title: err
					})
				})
			},
			//提交
			submit() {
				if (!this.Info.checked) {
					return uni.showToast({
						title: '请阅读用户注册协议',
						icon: 'none'
					})
				}
				register(this.Info).then((res) => {

					uni.showToast({
						title: res.msg,
						icon: 'none'
					})
					if (res.code == 1) {
						setTimeout(() => {
							uni.navigateTo({
								url: '/pages/login/login'
							})
						}, 1000)

					}
				})
			},
			//
			changeCheck(v){
				console.log(v);
			  this.Info.checked = v.detail.value[0];
			},
		}
	}
</script>

<style scoped lang="scss">
	page {
		background-color: white;
	}
</style>